<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
    </div>

    <template id="cpn">
        <div>
            <h1>当前计数：{{count}}</h1>
            <button v-on:click="add()">+</button>
            <button v-on:click="sub()">-</button>
        </div>
    </template>

    <script src="vue.js"></script>
    <script>
        Vue.component("cpn",{
            template: "#cpn",
            data(){
                return {
                    count: 0,
                }
            },
            methods: {
                add: function () {
                    //当前对象内需要加this
                    this.count = this.count + 1
                },
                sub: function () {
                    //当前对象内需要加this
                    this.count = this.count - 1
                }
            }
        })
        app = new Vue({
            //声明要绑定的id
            el: '#app',
            //数据对象 
            data: {
                
            },
            //methods用于定义方法
            methods: {
            }
        })
    </script>
</body>

</html>